package com.gc.gc.organ.service.impl;

import com.gc.gc.mybatis.entity.PtOrganEntity;
import com.gc.gc.mybatis.entity.PtUserEntity;
import com.gc.gc.mybatis.flexigrid.PadingRstType;
import com.gc.gc.mybatis.flexigrid.PagingBean;
import com.gc.gc.mybatis.ztree.ZtreeEntity;
import com.gc.gc.organ.entity.OrganSearchEntity;
import com.gc.gc.organ.repository.OrganDao;
import com.gc.gc.organ.service.OrganService;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Locale;

@Service
public class OrganServiceImpl implements OrganService {
    @Resource
    private OrganDao organDao;
    @Override
    public PadingRstType<PtOrganEntity> getOrganInfoListByPage(OrganSearchEntity search, PagingBean paging) {
        paging.deal(OrganSearchEntity.class);
        PagingBean newPa = new PagingBean();

        PadingRstType<PtOrganEntity> padingRstType = new PadingRstType<>();
        padingRstType.setPage(paging.getPage());
        List<PtOrganEntity> list = organDao.queryOrganListByPadding(search,paging);
        System.out.println(list);
        Integer total = organDao.queryUserListTotal(search);
        padingRstType.setRawRecords(list);
        padingRstType.setTotal(total);
        padingRstType.putItems();
        return padingRstType;
    }

    @Override
    public void delOrganByUuid(String organUuid) {
        organDao.delOrganByUuid(organUuid);
    }

    @Override
    public void bindingByUuid(String organUuid, String parentUuid) {
        organDao.bindingByUuid(organUuid,parentUuid);
    }

    @Override
    public void unboundByUuid(String organUuid) {
        organDao.unboundByUuid(organUuid);
    }

    @Override
    public void insertOrgan(String organUuid, String organName, String parentUuid, String DESCRIPTION) {
        LocalDateTime time = LocalDateTime.now();
        organDao.insertOrgan(organUuid,organName,parentUuid,DESCRIPTION,time);
    }

    @Override
    public void updateOrgan(String organUuid, String organUuidUpdate, String organName, String parentUuid, String DESCRIPTION) {

        organDao.updateOrgan(organUuid,organUuidUpdate,organName,parentUuid,DESCRIPTION);
    }

    @Override
    public PtOrganEntity selectSearchOrganEntityByOrganUuid(String organUuid) {
        return organDao.selectSearchOrganEntityByOrganUuid(organUuid);
    }

    @Resource
    private MessageSource messageSource;
    @Override
    public List<ZtreeEntity> getOrganZtreeList() {
        Locale locale = LocaleContextHolder.getLocale();
        String msgStr =messageSource.getMessage("user.role.info",null,locale);

        List<ZtreeEntity> list = organDao.getOrganZtreeList();

        return list;
    }

}
